package com.example.board_jojo;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        TextView TVMenu1 = (TextView)findViewById(R.id.TVMainMenu1);
        TextView TVMenu2 = (TextView)findViewById(R.id.TVMainMenu2);
        TextView TVMenu3 = (TextView)findViewById(R.id.TVMainMenu3);
        
        registerForContextMenu(TVMenu1);
        registerForContextMenu(TVMenu2);
        registerForContextMenu(TVMenu3);
        
        
    }

    
    
    
    
    

    @Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
    	int id = v.getId();
    	
    	switch (id) {
		case R.id.TVMainMenu1:
			menu.add(0, 101, 0, "선택메뉴1-1");
			menu.add(0, 102, 0, "선택메뉴1-2");
			
			break;

		case R.id.TVMainMenu2:
			menu.add(0, 201, 0, "선택메뉴2-1");
			menu.add(0, 202, 0, "선택메뉴2-2");
			menu.add(0, 203, 0, "선택메뉴2-3");
			
			break;
			
		case R.id.TVMainMenu3:
			SubMenu mainSubMenu1 = menu.addSubMenu("서브메뉴1");
			SubMenu mainSubMenu2 = menu.addSubMenu("서브메뉴1");
			
			mainSubMenu1.add(0, 30101, 0, "선택 서브메뉴1-1");
			mainSubMenu1.add(0, 30102, 0, "선택 서브메뉴1-2");
			mainSubMenu1.add(0, 30103, 0, "선택 서브메뉴1-3");


			mainSubMenu2.add(0, 30201, 0, "선택 서브메뉴2-1");
			mainSubMenu2.add(0, 30202, 0, "선택 서브메뉴2-2");
			mainSubMenu2.add(0, 30203, 0, "선택 서브메뉴2-3");
			
			break;	
		}
		super.onCreateContextMenu(menu, v, menuInfo);
	}







	@Override
	public boolean onContextItemSelected(MenuItem item) {
		Toast.makeText(getApplicationContext(), "선택한 메뉴 : [" + item.getTitle() + "]", Toast.LENGTH_SHORT).show();
		return super.onContextItemSelected(item);
	}







	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        new MainOptionMenu(this, item);
        return super.onOptionsItemSelected(item);
    }
}
